﻿using System.Collections.Generic;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace DatabaseGroup.SSIS.SourceAdapters.Model
{
    /// <summary>
    /// Provides functionality to read and update component configuration
    /// </summary>
    public interface IComponentModel
    {
        /// <summary>
        /// Gets or sets the name of the component
        /// </summary>
        string ComponentName { get; set; }

        /// <summary>
        /// Gets or sets the description of the component
        /// </summary>
        string ComponentDescription { get; set; }

        /// <summary>
        /// Gets the current file connection manager name the
        /// component is configured to use
        /// </summary>
        string FileConnectionName { get; }

        /// <summary>
        /// Gets the current connection string the 
        /// component is configured to use
        /// </summary>
        string ConnectionString { get; }

        /// <summary>
        /// Gets the number of currently configured standard output columns
        /// </summary>
        int StandardOutputColumns { get; }

        /// <summary>
        /// Gets or sets the components Locale ID
        /// </summary>
        int Locale { get; set; }

        /// <summary>
        /// Gets the value of a component custom property
        /// </summary>
        /// <typeparam name="T">The type of the value stored</typeparam>
        /// <param name="name">The name of the property</param>
        /// <returns>The value of the property</returns>
        T GetProperty<T>(string name);

        /// <summary>
        /// Sets the value of a component custom property
        /// </summary>
        /// <param name="name">The name of the custom property</param>
        /// <param name="value">The value to set the custom property to</param>
        void SetProperty(string name, object value);

        /// <summary>
        /// Triggers SSIS to prompt the user to create a new FILE connection manager
        /// </summary>
        /// <returns>The name of the new file connection, or null if none were created</returns>
        string RequestNewFileConnection();

        /// <summary>
        /// Gets the complete file path for a specific connection
        /// </summary>
        /// <param name="connectionName">The name of the file connection manager to use</param>
        /// <returns>The file path for the connection</returns>
        string GetFileConnectionByName(string connectionName);

        /// <summary>
        /// Configures the component to use a specific file connection manager
        /// </summary>
        /// <param name="connectionName">The name of the file connection manager to use</param>
        void SetFileConnectionByName(string connectionName);

        /// <summary>
        /// Validates the connection manager
        /// </summary>
        /// <param name="name">The name of the connection manager to validate</param>
        /// <returns>True if the file connection manager points to a valid file</returns>
        bool IsFileConnectionValid(string name);

        /// <summary>
        /// Deletes all columns in the component assigned to the standard output
        /// </summary>
        void ClearStandardOutputColumns();

        /// <summary>
        /// Inserts a new column to the component standard output based on
        /// the configured file column provided
        /// </summary>
        /// <param name="column">The ConfiguredFileColumn to base the new column from</param>
        void InsertStandardOutputColumn(ConfiguredFileColumn column);

        /// <summary>
        /// Returns a list of file connection manager names
        /// that are currently available to the component
        /// </summary>
        /// <returns>The list of file connection manager names</returns>
        List<string> GetAvailableFileConnectionNames();

        /// <summary>
        /// Gets the standard output column name for a column
        /// at a specific column index
        /// </summary>
        /// <param name="columnIndex">The zero-based column index</param>
        /// <returns>The standard output column name</returns>
        string GetStandardOutputColumnName(int columnIndex);

        /// <summary>
        /// Gets the disposition settings for a specific standard output column
        /// </summary>
        /// <param name="columnIndex">The zero-based index of the column</param>
        /// <param name="errorDisposition">The column error row disposition</param>
        /// <param name="truncationDisposition">The column truncation row disposition</param>
        void GetStandardOutputColumnDisposition(int columnIndex,
            out DTSRowDisposition errorDisposition, out DTSRowDisposition truncationDisposition);

        /// <summary>
        /// Sets a specific standard output column disposition configuration
        /// </summary>
        /// <param name="columnIndex">The zero-based column index to set the disposition on</param>
        /// <param name="errorDisposition">The column error row disposition to use</param>
        /// <param name="truncationDisposition">The column truncation row disposition to use</param>
        void SetStandardOutputColumnDisposition(int columnIndex, 
            DTSRowDisposition errorDisposition, DTSRowDisposition truncationDisposition);

        /// <summary>
        /// Sets the disposition configuration for the standard output
        /// </summary>
        /// <param name="errorDisposition">The error row disposition to use</param>
        /// <param name="truncationDisposition">The truncation row disposition to use</param>
        void SetStandardOutputDisposition(DTSRowDisposition errorDisposition, DTSRowDisposition truncationDisposition);

        /// <summary>
        /// Gets the disposition configuration for the standard output
        /// </summary>
        /// <param name="errorDisposition">The error row disposition</param>
        /// <param name="truncationDisposition">The truncation row disposition</param>
        void GetStandardOutputDisposition(out DTSRowDisposition errorDisposition, out DTSRowDisposition truncationDisposition);

        /// <summary>
        /// Queries the component configuration and reconfigures the error output 
        /// </summary>
        void ReconfigureErrorOutput();

        /// <summary>
        /// Queries the component configuration and sets up (or reconfigures)
        /// the log output accordingly
        /// </summary>
        void SetupLogOutput();
    }
}
